import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:get/get.dart';

///
/// 选择
///
class ParamPicker {

  static void show(title, context, List<String> list, {Function? onConfirm, int selecteds = 0}) {
    FocusScopeNode currentFocus = FocusScope.of(context);
    if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
      FocusManager.instance.primaryFocus!.unfocus();
    }

    var picker = Picker(
      adapter: PickerDataAdapter<String>(
        pickerData: list
      ),
      headerDecoration: const BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: Colors.black12, width: 0.3
          )
        )
      ),
      selecteds: [selecteds],
      cancelTextStyle: TextStyle(fontSize: 15.sp, color: Colors.grey),
      confirmTextStyle: TextStyle(fontSize: 15.sp, color: const Color(0xff499360)),
      changeToFirst: false,
      title: Text('$title', style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w500),),
      textAlign: TextAlign.left,
      selectedTextStyle:  TextStyle(fontSize: 16.sp, color: const Color(0xff323232)),
      columnPadding: EdgeInsets.all(20.w),
      textStyle: TextStyle(fontSize: 14.sp, color: const Color(0xff323232)),
      height: 240.w,
      onSelect: (picker, index, selected) {
      },
      onConfirm: (Picker picker, List value) async {
        onConfirm?.call(value[0]);
      },
      
    );

    showModalBottomSheet(
      context: Get.context!,
      backgroundColor: Colors.transparent,
      builder: (context) {
        return Material(
          color: Colors.white,
          borderRadius: const BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(10)
          ),
          child: Container(
            padding: const EdgeInsets.only(top: 4),
            child: picker.makePicker(null, true),
          )
        );
      }
    );
  }







  static void showDw(title, context, List list, {Function? onConfirm, int selecteds = 0}) {
    FocusScopeNode currentFocus = FocusScope.of(context);
    if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
      FocusManager.instance.primaryFocus!.unfocus();
    }

    var picker = Picker(
      adapter: PickerDataAdapter<String>(
        pickerData: JsonDecoder().convert(jsonEncode(list))
      ),
      selecteds: [selecteds, 0],
      headerDecoration: const BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: Colors.black12, width: 0.3
          )
        )
      ),
      // selecteds: [selecteds],
      cancelTextStyle: TextStyle(fontSize: 15.sp, color: Colors.grey),
      confirmTextStyle: TextStyle(fontSize: 15.sp, color: const Color(0xff499360)),
      changeToFirst: false,
      title: Text('$title', style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w500),),
      textAlign: TextAlign.left,
      selectedTextStyle:  TextStyle(fontSize: 16.sp, color: const Color(0xff323232)),
      columnPadding: EdgeInsets.all(20.w),
      textStyle: TextStyle(fontSize: 14.sp, color: const Color(0xff323232)),
      height: 240.w,
      onSelect: (picker, index, selected) {
      },
      onConfirm: (Picker picker, List value) async {
        onConfirm?.call(value[0]);
      },
      
    );

    showModalBottomSheet(
      context: Get.context!,
      backgroundColor: Colors.transparent,
      builder: (context) {
        return Material(
          color: Colors.white,
          borderRadius: const BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(10)
          ),
          child: Container(
            padding: const EdgeInsets.only(top: 4),
            child: picker.makePicker(null, true),
          )
        );
      }
    );
  }

}